Skip to content

Refactor: move hotkey display-string formatting onto HotKeyCombination#8

Merged
GamalAnwar merged 1 commit into
masterfrom
claude/solid-refactor-hotkey-display
Jun 17, 2026
Merged

Refactor: move hotkey display-string formatting onto HotKeyCombination#8
GamalAnwar merged 1 commit into
masterfrom
claude/solid-refactor-hotkey-display

Conversation

@GamalAnwar

Copy link
Copy Markdown
Contributor

Summary

First PreferencesWindow slice. The shortcut row built its ⇧⌘1-style label inline in the view's displayText, including a 33-entry macOS keycode→label map (keyName) embedded in the SwiftUI struct.

This moves the formatting onto the model type, where modifierFlags already lives:

combo.displayString              // "⇧⌘1" — modifiers in ⌃⌥⇧⌘ order + key label
HotKeyCombination.keyName(23)    // "5"

The view keeps only its genuine UI states:

private var displayText: String {
    if isRecording { return "Press shortcut…" }
    if current.keyCode == 0 { return "None" }
    return current.displayString
}

Scope / safety

  • Behavior-preserving — same symbols, same ordering, same Key<code> fallback.
  • The keycode map's non-sequential quirk (kVK_ANSI_5 = 23, _6 = 22) is preserved and now has a regression test — this is the exact mapping that was previously swapped and mis-fired the recorder.
  • event.modifierFlags uses in the live key-capture code are untouched (unrelated NSEvent accessor).

Tests

HotKeyCombinationDisplayTests (6 cases): command+shift digit, full ⌃⌥⇧⌘ ordering, non-sequential digit keycodes, unknown-keycode fallback, empty string for keyCode 0, and special-key labels (Space/Return/Esc).

🤖 Generated with Claude Code


Generated by Claude Code

PreferencesWindow's shortcut row built its '⇧⌘1'-style label inline, including a
33-entry macOS keycode->label map embedded in the view. Move it onto the model
type as HotKeyCombination.displayString / .keyName(_:), where modifierFlags
already lives. The view keeps only its UI states ('None', 'Press shortcut…').

Behavior-preserving. Adds HotKeyCombinationDisplayTests (6 cases), including a
regression guard for the non-sequential digit keycodes (kVK_ANSI_5=23, _6=22).
@GamalAnwar GamalAnwar merged commit 6dc2b2b into master Jun 17, 2026
1 check passed
@GamalAnwar GamalAnwar deleted the claude/solid-refactor-hotkey-display branch June 18, 2026 07:36
GamalAnwar added a commit that referenced this pull request Jun 18, 2026
#8)

Move PreferencesWindow's inline shortcut-label formatting (modifier symbols +
33-entry macOS keycode->label map) onto HotKeyCombination.displayString /
.keyName(_:), beside the existing modifierFlags. View keeps only its UI states.
Behavior-preserving. Adds HotKeyCombinationDisplayTests (6 cases) incl. a guard
for the non-sequential digit keycodes. CI green.
GamalAnwar added a commit that referenced this pull request Jun 18, 2026
#8)

Move PreferencesWindow's inline shortcut-label formatting (modifier symbols +
33-entry macOS keycode->label map) onto HotKeyCombination.displayString /
.keyName(_:), beside the existing modifierFlags. View keeps only its UI states.
Behavior-preserving. Adds HotKeyCombinationDisplayTests (6 cases) incl. a guard
for the non-sequential digit keycodes. CI green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants